-- 仙女冈布奥

function initFairySlime(self, buildingInfo, dbase, pos)
    if type(buildingInfo) ~= "table" then
        -- 没要求，配置错误
        error("获取不到仙女冈布奥配置！");
        return;
    end

    -- 触发的事件id，根据是否拥有匹诺曹确定
    local eventId = 118;
    local petId = SlimeEventM.query(eventId, "dbase")["pet_id"];
    local summonId = SlimeEventM.query(eventId, "dbase")["summon_id"];
    if PetM.isActivated(petId) then
        eventId = 119;
    end

    -- 金币消耗
    local bonusArgs = SlimeEventM.query(eventId, "bonus_args")
    local cost = bonusArgs["cost"][1];

    -- 转化匹诺曹
    local function okFun()
        -- 金币足够否
        if cost[1] ~= 2 or cost[2] ~= "money" then
            -- 配置错误
            error("仙女冈布奥扣除配置错误！");
            return;
        end

        -- 判断玩家金钱是否足够
        if ME.user.dbase:query(cost[2], 0) < cost[3] then
            -- 关闭建筑界面
             UIMgr.getCurrentScene():removeFormByName("UIBuildingView2");
            -- 显示商城购买金币界面
            showBuyMoneyTip();
            return;
        end

        -- 提示
        alert(buildingInfo["bonus_tip"]);

        -- 尝试尝试触发
        DungeonActionM.go("slime_event", pos, eventId);

        -- 建筑消失
        playBuildingDisappear(self);
    end

    -- TODO: 点击
    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 格子失效了
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 匹诺曹召唤物是否还活着
            if SummonM.calcExistedSummon(summonId) > 0 then
                local dialog = string.format(buildingInfo["dialog"], cost[3]);
                self:openBuildingView2(okFun, nil, nil, nil, dialog);
            else
                self:openBuildingView(nil, nil, buildingInfo["dialog2"], getLocStr("leave"));
            end

            AudioM.playFx("slime_adventurer_app");
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
    self.icon:addTouchEventListener(onClicked);
end

